//
//  Today_today_Slice_Cell.m
//  Time
//
//  Created by dllo on 16/7/18.
//  Copyright © 2016年 司昌宝. All rights reserved.
//

#import "Today_today_Slice_Cell.h"
#import "SCB_Today_TodayContentModel.h"

@interface Today_today_Slice_Cell ()

@end

@implementation Today_today_Slice_Cell

-(void)dealloc {
    [_contentImageView release];
    [_sliceImageView release];
    [_titleLabel release];
    [_contentLabel release];
    [_userinfoView release];
    [_shareButton release];
    [_likesButton release];
    [_likesLabel release];
    [_model release];
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //        self.contentView.backgroundColor = [UIColor greenColor];
        
        self.contentImageView = [[UIImageView alloc] init];
        self.contentImageView.backgroundColor = [UIColor orangeColor];
        [self.contentView addSubview:self.contentImageView];
        [_contentImageView release];
        
        UIBlurEffect *blu = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
        UIVisualEffectView *view = [[UIVisualEffectView alloc] initWithEffect:blu];
        [self.contentImageView addSubview:view];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentImageView.mas_left).offset(0);
            make.right.equalTo(self.contentImageView.mas_right).offset(0);
            make.top.equalTo(self.contentImageView.mas_top).offset(0);
            make.bottom.equalTo(self.contentImageView.mas_bottom).offset(0);
        }];
        view.alpha = 1.0;
        
        self.sliceImageView = [[UIImageView alloc] init];
        [self.contentImageView addSubview:self.sliceImageView];
        [_sliceImageView release];
        
        self.sliceLabel = [[UILabel alloc] init];
        [self.contentImageView addSubview:self.sliceLabel];
        [_sliceLabel release];
        
        self.titleLabel = [[UILabel alloc] init];
        //        self.titleLabel.backgroundColor = [UIColor yellowColor];
        [self.contentView addSubview:self.titleLabel];
        [_titleLabel release];
        
        self.contentLabel = [[UILabel alloc] init];
        //        self.contentLabel.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:self.contentLabel];
        [_contentLabel release];
        
        self.userinfoView = [[UserinfoView alloc] init];
        //        self.userinfoView.backgroundColor = [UIColor cyanColor];
        [self.contentView addSubview:self.userinfoView];
        [_userinfoView release];
        
        self.shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.shareButton.hidden = YES;
        [self.shareButton addTarget:self action:@selector(shareButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.shareButton];
        [_shareButton release];
        
        self.likesButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.likesButton.hidden = YES;
        [self.likesButton addTarget:self action:@selector(likesButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.likesButton];
        [_likesButton release];
        
        self.likesLabel = [[UILabel alloc] init];
        self.likesLabel.hidden = YES;
        [self.contentView addSubview:self.likesLabel];
        [_likesLabel release];
        
    }
    return self;
}
/**
 *  分享按钮点击方法
 *
 *  @param button 参数还是按钮
 */
-(void)shareButtonAction:(UIButton *)button{
    NSLog(@"分享");
}
/**
 *  收藏按钮点击方法
 *
 *  @param button 参数按钮
 */
-(void)likesButtonAction:(UIButton *)button{
    NSLog(@"收藏");
}


-(void)layoutSubviews{
    [super layoutSubviews];
    
    [self.shareButton setImage:[UIImage imageNamed:@"分享"] forState:UIControlStateNormal];
    //    self.likesImageView.image = [UIImage imageNamed:@"收藏 (3)"];
    [self.likesButton setImage:[UIImage imageNamed:@"收藏 (3)"] forState:UIControlStateNormal];
    self.likesLabel.font = [UIFont systemFontOfSize:12.0];
    self.contentLabel.font = [UIFont systemFontOfSize:15.0];
    self.contentLabel.textColor = [UIColor grayColor];
    
    
    [self.contentImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(10);
        make.right.equalTo(self.contentView.mas_right).offset(-10);
        make.top.equalTo(self.contentView.mas_top).offset(0);
        make.bottom.equalTo(self.contentView.mas_top).offset(250);
    }];
    
    [self.sliceImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentImageView.mas_centerX).offset(0);
        make.centerY.equalTo(self.contentImageView.mas_centerY).offset(0);
        make.width.mas_equalTo(SWIDTH * 0.4);
        make.height.mas_equalTo(SWIDTH * 0.4);
    }];
    
    [self.sliceLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.sliceImageView.mas_centerX).offset(0);
        make.width.mas_equalTo(SWIDTH * 0.4);
        make.top.equalTo(self.sliceImageView.mas_bottom).offset(10);
        make.top.equalTo(self.sliceImageView.mas_bottom).offset(40);
    }];
    self.sliceLabel.textColor = [UIColor whiteColor];
    self.sliceLabel.font = [UIFont systemFontOfSize:12.0];
    self.sliceLabel.textAlignment = NSTextAlignmentCenter;
    
    CGFloat titleHeight = [Tools getTextHeight:self.model.todayContent.title withWidth:SWIDTH - 20 withFontSize:17.0];
    self.titleLabel.numberOfLines = 0;
    [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(10);
        make.right.equalTo(self.contentView.mas_right).offset(-10);
        make.top.equalTo(self.contentImageView.mas_bottom).offset(30);
//        make.bottom.equalTo(self.contentImageView.mas_bottom).offset(60);
        make.height.mas_equalTo(titleHeight + 10);
    }];
    
    CGFloat contentHeight = [Tools getTextHeight:self.model.todayContent.text withWidth:SWIDTH - 20 withFontSize:15.0];
    self.contentLabel.numberOfLines = 0;
    [self.contentLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(10);
        make.right.equalTo(self.contentView.mas_right).offset(-10);
        make.top.equalTo(self.titleLabel.mas_bottom).offset(10);
//        make.bottom.equalTo(self.titleLabel.mas_bottom).offset(30);
        make.height.mas_equalTo(contentHeight + 10);
    }];
    
    [self.userinfoView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(10);
        make.right.equalTo(self.shareButton.mas_left).offset(-10);
        make.top.equalTo(self.contentLabel.mas_bottom).offset(20);
        make.bottom.equalTo(self.contentLabel.mas_bottom).offset(60);
    }];
    
    [self.likesLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_right).offset(-40);
        make.right.equalTo(self.contentView.mas_right).offset(-10);
        make.top.equalTo(self.contentLabel.mas_bottom).offset(34);
        make.bottom.equalTo(self.contentLabel.mas_bottom).offset(46);
    }];
    
    [self.likesButton mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.likesLabel.mas_left).offset(-20);
        make.right.equalTo(self.likesLabel.mas_left).offset(-8);
        make.top.equalTo(self.contentLabel.mas_bottom).offset(34);
        make.bottom.equalTo(self.contentLabel.mas_bottom).offset(46);
    }];
    
    [self.shareButton mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.likesButton.mas_left).offset(-40);
        make.right.equalTo(self.likesButton.mas_left).offset(-28);
        make.top.equalTo(self.contentLabel.mas_bottom).offset(34);
        make.bottom.equalTo(self.contentLabel.mas_bottom).offset(46);
    }];
    
}

-(void)setModel:(SCB_Today_TodayContentModel *)model{
    if (_model != model){
        [_model release];
        _model = [model retain];
    }
    [self.contentImageView setImageWithURL:[NSURL URLWithString:model.todayContent.coverimg] placeholderImage:nil];
    [self.sliceImageView setImageWithURL:[NSURL URLWithString:model.todayContent.coverimg] placeholderImage:nil];
    self.sliceLabel.text = [NSString stringWithFormat:@"%@/%@条内容/%@人订阅",model.todayContent.scbCollinfo.tag,model.todayContent.scbCollinfo.contains,model.todayContent.scbCollinfo.subscribes];
    self.titleLabel.text = model.todayContent.title;
    self.contentLabel.text = model.todayContent.text;
    self.userinfoView.scbUserinfo = model.todayContent.scbUserinfo;
    self.userinfoView.pubdate = model.pubdate;
    self.likesLabel.text = [NSString stringWithFormat:@"%@",model.todayContent.likes];
    self.likesLabel.textAlignment = NSTextAlignmentRight;
}


@end
